package com.his.dictresource.service.impl;

import com.his.dictresource.dao.DictResourceItemMapper;
import com.his.dictresource.entity.DictResource;
import com.his.dictresource.entity.DictResourceItem;
import com.his.dictresource.entity.DictResourceItems;
import com.his.dictresource.service.DictResourceItemService;
import com.his.dictresource.vo.DictResourceItemVo;
import com.his.dictresource.vo.DictResourceVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.util.BeanUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DictResourceItemServiceImpl implements DictResourceItemService {
    @Resource
    private DictResourceItemMapper dictResourceItemMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<DictResourceItems> selectDictResourceItemList(DictEmployee dictEmployee, DictResourceVo dictResourceVo) {
        DictResource dictResource=BeanUtil.copyBean(dictResourceVo,DictResource.class);
        //科室与医生id都有
        if(!dictResource.getOrgid().equals("") && !dictResource.getResourceid().equals("")){
            return dictResourceItemMapper.rsitem_list(dictResource.getResourceid(),dictEmployee.getHOSPID());
        }else{
            return dictResourceItemMapper.rsitem_list(dictResource.getOrgid(),dictEmployee.getHOSPID());
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
        public void insertDictResourceItem(DictResourceItemVo dictResourceItemVo) {
            DictResourceItem dictResourceItem = BeanUtil.copyBean(dictResourceItemVo,DictResourceItem.class);
            dictResourceItemMapper.rsitem_del(dictResourceItem.getItemid(),dictResourceItem.getResourcetypeid());
            dictResourceItemMapper.rsitem_add(dictResourceItem);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteDictResourceItem(String itemId,String resourceTypeId) {
        dictResourceItemMapper.rsitem_del(itemId,resourceTypeId);
    }
}
